import request from "@/utils/request";
import type { PageResult, PageParams } from "@/types";

// 举报创建请求
export interface ReportCreateRequest {
  targetType: number; // 1-帖子，2-评论，3-用户，4-悄悄话
  targetId: number;
  reasonType: number; // 1-垃圾信息，2-违法违规，3-涉黄涉暴，4-恶意骚扰，5-其他
  reasonDetail?: string;
  evidenceUrls?: string[];
}

// 举报信息
export interface ReportDTO {
  id: number;
  targetType: number;
  targetTypeName: string;
  targetId: number;
  reasonType: number;
  reasonTypeName: string;
  reasonDetail?: string;
  evidenceUrls: string[];
  status: number;
  statusName: string;
  handleResult?: string;
  createTime: string;
  handleTime?: string;
  reporter: {
    id: number;
    username: string;
    nickname?: string;
    avatar?: string;
  };
  handler?: {
    id: number;
    username: string;
    nickname?: string;
  };
  targetContent: {
    id: number;
    title: string;
    content?: string;
    authorName?: string;
    createTime?: string;
    exists: boolean;
  };
}

// 举报处理请求
export interface ReportHandleRequest {
  status: number; // 1-已处理，2-已驳回，3-已删除目标内容
  handleResult?: string;
  deleteTargetContent?: boolean;
}

// 举报统计信息
export interface ReportStatsDTO {
  totalReports: number;
  pendingReports: number;
  todayReports: number;
  reasonTypeStats: Array<[number, number]>;
  targetTypeStats: Array<[number, number]>;
  statusStats: Array<[number, number]>;
}

/**
 * 创建举报
 */
export function createReport(data: ReportCreateRequest): Promise<ReportDTO> {
  return request({
    url: "/reports",
    method: "post",
    data,
  });
}

/**
 * 获取用户的举报记录
 */
export function getUserReports(params?: PageParams): Promise<PageResult<ReportDTO>> {
  return request({
    url: "/reports/my",
    method: "get",
    params,
  });
}

/**
 * 获取举报详情
 */
export function getReportById(reportId: number): Promise<ReportDTO> {
  return request({
    url: `/reports/${reportId}`,
    method: "get",
  });
}

/**
 * 获取举报列表（管理员功能）
 */
export function getReports(params: {
  status?: number;
  targetType?: number;
  reasonType?: number;
  page?: number;
  size?: number;
}): Promise<PageResult<ReportDTO>> {
  return request({
    url: "/reports/admin",
    method: "get",
    params,
  });
}

/**
 * 获取待处理举报列表（管理员功能）
 */
export function getPendingReports(params?: PageParams): Promise<PageResult<ReportDTO>> {
  return request({
    url: "/reports/admin/pending",
    method: "get",
    params,
  });
}

/**
 * 处理举报（管理员功能）
 */
export function handleReport(reportId: number, data: ReportHandleRequest): Promise<ReportDTO> {
  return request({
    url: `/reports/${reportId}/handle`,
    method: "put",
    data,
  });
}

/**
 * 获取举报统计信息（管理员功能）
 */
export function getReportStats(): Promise<ReportStatsDTO> {
  return request({
    url: "/reports/admin/stats",
    method: "get",
  });
}
